class Student:
    def __init__(self):
        self.name = ''
        self.gender = ''
        self.age = 0

    def sayHello(self):
        print('hello!')


s1 = Student()
s1.name = '张三'
s1.gender = '男'
s1.age = 18
s1.sayHello()

s2 = Student()
s2.name = '李四'
s2.gender = '女'
s2.age = 16

s = []
s.append(s1)
s.append(s2)

# 中文乱码问题
with open('data.txt', 'w', encoding='utf-8') as f:

    for item in s:
        # 格式化字符串 format string
        f.write(f'{item.name} {item.gender} {item.age}\n')

        # f.write(item.name)
        # f.write(' ')
        # f.write(item.gender)
        # f.write(' ')
        # f.write(str(item.age))
        # f.write('\n')



